/**
 * 动态加载外部组件和css
 * @param {string} name 组件名字
 * @param {string} path 组件目录
 * @returns {Promise<*>} 组件实例
 */
export function loadCommAndCss(name, path = '/com/') {
    const src = `${path}${name}/${name}-umd.js`
    return new Promise((resolve, reject) => {
        if (!src || !name) return
        const script = document.createElement('script')
        script.async = true
        script.src = src
        // script.type = 'module'
        document.getElementsByTagName('head')[0].appendChild(script)
        script.onload = () => {
            window[name].name = name
            /*if (window[name][name].__scopeId) {
                // 如果存在css就加载
                const link = document.createElement('link')
                link.type = 'text/css'
                link.rel = 'stylesheet'
                link.href = `${path}${name}/${name}.css`
                document.getElementsByTagName('head')[0].appendChild(link)
            }*/
            resolve(window[name])
        }
        script.onerror = (e) => {
            reject(e)
            console.log(e)
        }
    })
}

/**
 * config 格式成自己
 * @param {Object} config
 */
export function configFormat(config){

}
